package com.charon.auth.demo.entity;

import com.charon.auth.demo.annotation.MyConstraint;
import com.fasterxml.jackson.annotation.JsonView;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import java.util.Date;

/**
  *@ClassName: User
  *@Description: 测试用户实体
  *@Author: Charon [248135724@qq.com]
  *@Date: 2019/1/12 0012 15:13
  *@Version: 1.0
  */
public class User {

    public User() {

    }

    /**
     * Json视图
     */
    public interface UserSimpleView{};
    public interface UserDetailView extends UserSimpleView{};
    //使用自定义注解
    @MyConstraint(message = "这是一个测试")
    @NotNull(message="用户名不能为空")
    private String userName;
    @NotNull(message="年龄不能为空")
    private Integer age;
    @NotBlank(message = "密码不能为空")
    private String password;
    private String id;
    /**
     * @NotEmpty 用在集合类上面
     * @NotBlank 用在String上面
     * @NotNull 用在基本类型上
     * 需要结合@Valid使用
     * BindingResult 和@Valid结合使用，在不符合@Valid的校验时，可以通过BindingResult进入方法，打印错误
     */
    @NotNull(message = "生日不能为空")
    @Past(message="生日必须是过去时间")
    private Date birthday;

    /**
     * 在展示详细视图的时候，也会将父接口的视图(userName)展示出来
     * @return
     */
    @JsonView(UserDetailView.class)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @JsonView(UserSimpleView.class)
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @JsonView(UserSimpleView.class)
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                ", id='" + id + '\'' +
                ", birthday=" + birthday +
                '}';
    }
}
